package com.usmarter.server.services;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.usmarter.model.QuestionEntity;
import com.usmarter.server.db.MyDB;

@Service
@Path("/question")
public class QuestionRestService {

	@Autowired
	private MyDB myDB;

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public String createQuestion(@QueryParam("q") String question) {
		QuestionEntity entity = new QuestionEntity();
		entity.setHeader("My Header");
		entity.setBody(question);
		entity.setUserID(1);
		long id = myDB.createQuestion(entity);
		return "Added question #"+id;
	}

	@GET
	@Path("/{id}")
	@Produces(MediaType.APPLICATION_JSON)
	public String getQuestion(@PathParam("id") long id) {
		return myDB.getQuestion(id).getBody();
	}
}
